package com.example.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.app.R;
import com.example.app.User;

import java.util.List;

public class SACAdapter extends BaseAdapter {

    private List<User> data;
    private Context context;

    public SACAdapter(List<User>data,Context context){
        this.data=data;
        this.context=context;
    }

    @Override
    public int getCount() {
        return data.size()+1;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        SACAdapter.ViewHolder viewHolder;
        if(view==null)
        {
            viewHolder=new SACAdapter.ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.user_count,viewGroup,false);
            viewHolder.userName=view.findViewById(R.id.uc_user);
            viewHolder.userPassword= view.findViewById(R.id.uc_password);
            view.setTag(viewHolder);
        }else {
            viewHolder = (SACAdapter.ViewHolder) view.getTag();
        }
        if(i==0)
        {
            viewHolder.userName.setText("用户名");
            viewHolder.userPassword.setText("密码");
        }
        else{
            int t=i-1;
            viewHolder.userName.setText(data.get(t).getName());
            viewHolder.userPassword.setText(data.get(t).getPassword());
        }


        return view;
    }

    private final class ViewHolder{
        TextView userName;
        TextView userPassword;
    }
}
